﻿using CloudStorageLight.WpfClient.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Xml.Serialization;
using ViewMaker;
using ViewMaker.Core;
using ViewMaker.Core.Controls;

namespace CloudStorageLight.WpfClient
{
    [View(typeof(FolderMapWindow))]
    [ViewProperty(ViewMaker.Core.Controls.ControlViewControl.Properties.WindowResizeMode, "NoResize")]
    public class FolderMapVM : ViewModelBase
    {
        public string Path { get; private set; }


        public string LocalFolder
        {
            get { return _LocalFolder; }
            set { _LocalFolder = value; OnPropertyChanged("LocalFolder"); }
        }
        private string _LocalFolder;
    

        public FolderMapVM(string path)
        {
            this.Path = path;
        }

        //public ICommand Save { get { 
            
        //    return CreateCommand((x)=>{
        //        var p = BlobDataManager.Instance.FolderMappings.Where(y => y.Path == Path).FirstOrDefault();
        //        if (p == null)
        //        {
        //            if (!string.IsNullOrEmpty(LocalFolder))
        //            {
        //                BlobDataManager.Instance.FolderMappings.Add(new FolderMapItem { Path = Path, LocalFolder = LocalFolder });
        //            }
        //        }
        //        else
        //        {
        //            if (!string.IsNullOrEmpty(LocalFolder))
        //            {
        //                p.LocalFolder = LocalFolder;
        //            }
        //            else
        //            {
        //                BlobDataManager.Instance.FolderMappings.Remove(p);
        //            }
        //        }
        //        BlobDataManager.Instance.SaveFolderMapFile();
        //        ExecuteViewCommand("Close");
        //    });
        //}
        //}

        public ICommand Close { get { return CreateViewCommand("Close"); } }

        public ICommand SelectFolder { get { return CreateCommand(ShowFolderDailog); } }

        private void ShowFolderDailog(object arg)
        {
            var dialog = new System.Windows.Forms.FolderBrowserDialog();
            var result = dialog.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                this.LocalFolder = dialog.SelectedPath;
            }
 
        }
    }

    public class FolderMapItem
    {
        public string Path { get; set; }
        public string LocalFolder { get; set; }
    }
}
